<?php

namespace app\web\controller;

use think\Controller;
use think\Request;

class Staff extends Controller
{
    public function logIn($phone='',$password='')
    {
        if(!$phone){
            return ['code'=>1,'msg'=>'请输入电话号'];
        }
        if(!$password){
            return ['code'=>2,'msg'=>'请输入密码'];
        }
        $data = model('common/Staff')->get_one_from_phone($phone);
        if(!$data){
            return ['code'=>3,'msg'=>'手机号错误'];
        }
        if($data['password'] != md5($password)){
            return ['code'=>4,'msg'=>'密码错误'];
        }
        $clientkey = $data['id'] . "\t" . rand(100,999) . "\t";
        $token = explode("\t", model('common/Staff')->ClientKey($clientkey));
        return ['code'=>0,'msg'=>'登录成功','data'=>['token'=>$token]];
    }
}
